<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :cities="cities" :hotCities="hotCities" :letter="letter"></city-list>
    <city-alphabet :cities="cities" @change="handleLetterChange"></city-alphabet>
  </div>
</template>

<script>
import axios from 'axios'
import cityHeader from './components/Header.vue'
import citySearch from './components/Search.vue'
import cityList from './components/List.vue'
import cityAlphabet from './components/Alphabet.vue'
export default {
  name: 'pagescity',
  data() {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  components: { cityHeader, citySearch, cityList, cityAlphabet },
  methods: {
    getCityinfo() {
      axios.get('/api/city.json').then(this.handleGetCityInfoSucc)
    },
    handleGetCityInfoSucc(res) {
      console.log(res)
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.cities = data.cities
        this.hotCities = data.hotCities
      }
    },
    handleLetterChange(letter) {
      // console.log(letter)
      // 父组件就接收到了event.target.innerText这个letter
      this.letter = letter // emit船体的信息在父组件city中被拿到，还要给list
    }
  },
  mounted() {
    this.getCityinfo()
  }
}
</script>

<style scoped>
</style>